import javax.media.opengl.GL2;


public class Vehicle {
	
	static final int leftRearIndex = Constants.leftRearIndex;
	static final int rightRearIndex = Constants.rightRearIndex;
	static final int frontIndex = Constants.frontIndex;	
	static final int xIndex = Constants.xIndex;
	static final int yIndex = Constants.yIndex;
	static final int zIndex = Constants.zIndex;
	static public final float height = 1.0f;
	static public final float width = 2.0f; 
	static public final float length = 4.0f;
	
	public Vehicle() {
		
	}
	
	public void draw(GL2 gl, float[][] vehicleMatrix) {
		float centerX = (vehicleMatrix[leftRearIndex][xIndex] + vehicleMatrix[rightRearIndex][xIndex]) / 2.0f;
		float centerY = (vehicleMatrix[leftRearIndex][yIndex] + vehicleMatrix[rightRearIndex][yIndex]) / 2.0f;
		float centerZ = (vehicleMatrix[leftRearIndex][zIndex] + vehicleMatrix[rightRearIndex][zIndex]) / 2.0f;
		float midZ = (centerZ + length / 4.0f);
		// back
		gl.glBegin(GL2.GL_POLYGON);
		gl.glColor3f(0.0f, 0.0f, 1.0f);
		gl.glVertex3f(vehicleMatrix[leftRearIndex][xIndex], vehicleMatrix[leftRearIndex][yIndex], vehicleMatrix[leftRearIndex][zIndex]);
		gl.glVertex3f(vehicleMatrix[rightRearIndex][xIndex], vehicleMatrix[rightRearIndex][yIndex], vehicleMatrix[rightRearIndex][zIndex]);
		gl.glVertex3f(centerX, centerY + height, midZ);
		gl.glEnd();
		// left
		gl.glBegin(GL2.GL_POLYGON);
		gl.glColor3f(0.0f, 1.0f, 0.0f);
		gl.glVertex3f(vehicleMatrix[frontIndex][xIndex], vehicleMatrix[frontIndex][yIndex], vehicleMatrix[frontIndex][zIndex]);
		gl.glVertex3f(vehicleMatrix[leftRearIndex][xIndex], vehicleMatrix[leftRearIndex][yIndex], vehicleMatrix[leftRearIndex][zIndex]);
		gl.glVertex3f(centerX, centerY + height, midZ);
		gl.glEnd();
		//right
		gl.glBegin(GL2.GL_POLYGON);
		gl.glColor3f(1.0f, 0.0f, 0.0f);
		gl.glVertex3f(vehicleMatrix[frontIndex][xIndex], vehicleMatrix[frontIndex][yIndex], vehicleMatrix[frontIndex][zIndex]);
		gl.glVertex3f(vehicleMatrix[rightRearIndex][xIndex], vehicleMatrix[rightRearIndex][yIndex], vehicleMatrix[rightRearIndex][zIndex]);
		gl.glVertex3f(centerX, centerY + height, midZ);
		gl.glEnd();
		//bottom
		gl.glBegin(GL2.GL_POLYGON);
		gl.glColor3f(1.0f, 1.0f, 1.0f);
		gl.glVertex3f(vehicleMatrix[frontIndex][xIndex], vehicleMatrix[frontIndex][yIndex], vehicleMatrix[frontIndex][zIndex]);
		gl.glVertex3f(vehicleMatrix[rightRearIndex][xIndex], vehicleMatrix[rightRearIndex][yIndex], vehicleMatrix[rightRearIndex][zIndex]);
		gl.glVertex3f(vehicleMatrix[leftRearIndex][xIndex], vehicleMatrix[leftRearIndex][yIndex], vehicleMatrix[leftRearIndex][zIndex]);
		gl.glEnd();
	}
}
